package top.llove.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.llove.config.impl.MyHandlerInterceptor;


/**
 * Web配置
 * @author: 幸会
 * @date: 2021/6/6 15:14
 * @email: 1846724873@qq.com
 * @description: WebConfig
 * version: 1.0
 */
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private MyHandlerInterceptor myHandlerInterceptor; // 自定义过滤器


    /**
     * 全局跨域配置
     * @author: 幸会
     * @date: 2021/6/4 11:40
     * @description: addCorsMappings
     * @param registry
     * @return
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .maxAge(3600)
                .allowedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials", "")
                .allowCredentials(true);
    }


    /**
     * 过滤器配置
     * @author: 幸会
     * @date: 2021/6/4 11:40
     * @description: addInterceptors
     * @param registry
     * @return
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myHandlerInterceptor);
    }

}